package cc.linker.steplink.crm.commons.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
/**
 * 序列化成json时保留小数设定
 * @author Administrator
 *
 */
public class CustomDecimalSerialize extends JsonSerializer<BigDecimal> {  
	  
    private DecimalFormat df = new DecimalFormat("#.##");  
  
    @Override  
    public void serialize(BigDecimal value, JsonGenerator jgen,  
            SerializerProvider provider) throws IOException,  
            JsonProcessingException {
    	df.setRoundingMode(RoundingMode.FLOOR);
        jgen.writeString(df.format(value));  
    }  
}